package com.ymatou.iapi.productmanager.testcase;

import com.ymatou.iapi.productmanager.parameter.UpdateProductCatalogDto;
import com.ymatou.iapi.productmanager.parameter.UpdateProductCatalogsBean;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productmanager.parameter.product.CatalogSaveModel;
import com.ymatou.iapi.productmanager.service.AddSellerProductCall;
import com.ymatou.iapi.productmanager.service.UpdateProductCatalogsCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.business.service.ProductManagerCallServiceV3;
import com.ymttest.database.model.YmtCatalogsI;
import com.ymttest.database.sqlwapper.YmtCatalogsIWapper;
import com.ymttest.database.sqlwapper.YmtProductsIWapper;
import com.ymttest.utils.EnvSetup;
import org.json.JSONObject;
import org.junit.*;
import org.junit.experimental.categories.Category;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Ts_UpdateProductCatalogsV2 {
	
	private static UpdateProductCatalogsCall updateProductCatalogsCall = new UpdateProductCatalogsCall();
	private static Integer sellerId = Integer.valueOf(EnvSetup.getData("productsellerid"));
	private static int sellerId1 = Integer.parseInt(EnvSetup.getData("globalSellerId"));
	private static String sellerName = EnvSetup.getData("productsellername");
	private static YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
	private static UpdateProductCatalogsBean updateProductCatalogsBean = new UpdateProductCatalogsBean();
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("更新规格库存接口");
		//SqlMapperFactory.getIntergratedProductMapper().updateProductoffSale(sellerId);
	}
	
	@Before
	public void caseUp() {
	}
	
	@AfterClass
	public static void tearDown() {
		Logger.generateResult(updateProductCatalogsCall.getOpurl());
	}
	
	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateProductCatalogs_001() {
		Logger.start(true,"多规格普通商品修改价格和库存,包含num,newprice,vipprice,为0场景");
		try{
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();

			List<String> catalogIds = ymtCatalogsIWapper.selectCatalogsByProductId(productId).
					stream().map(x->x.getsCatalogId()).collect(Collectors.toList());
			
			//批量修改，num,newprice,vipprice,为0场景
			UpdateProductCatalogsBean updateCatalogBean = new UpdateProductCatalogsBean();
			updateCatalogBean.setProductID(productId);
			updateCatalogBean.setUserID(sellerId);
			
			UpdateProductCatalogDto updateCatalogDto = new UpdateProductCatalogDto();
			updateCatalogDto.setCatalogId(catalogIds.get(0));
			updateCatalogDto.setUserId(sellerId);
			updateCatalogDto.setPrice(50);
			
			UpdateProductCatalogDto updateCatalogDto2 = new UpdateProductCatalogDto();
			updateCatalogDto2.setCatalogId(catalogIds.get(1));
			updateCatalogDto2.setUserId(sellerId);
			updateCatalogDto2.setPrice(41);
			updateCatalogBean.setCatalogs(Arrays.asList(updateCatalogDto,updateCatalogDto2));
			
			JSONObject ret = updateProductCatalogsCall.callAndGetReturnData(updateCatalogBean);
			Logger.verifyEquals(200, ret.getInt("Code"), "返回码应为200");
			Thread.sleep(5000);
			checkPriceAndStock(updateCatalogBean);
			
			//===================================================================================================================
			//批量修改，num,newprice,vipprice,都不为0场景
			updateCatalogDto.setNum(20);
			updateCatalogDto.setNewCustomerPrice(49);
			updateCatalogDto.setVipPrice(48);
			
			updateCatalogDto2.setNum(19);
			updateCatalogDto2.setNewCustomerPrice(39);
			updateCatalogDto2.setVipPrice(38);
			
			ret = updateProductCatalogsCall.callAndGetReturnData(updateCatalogBean);
			Logger.verifyEquals(200, ret.getInt("Code"), "返回码应为200");
			Thread.sleep(5000);
			checkPriceAndStock(updateCatalogBean);
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateProductCatalogs_002() {
		Logger.start(true,"多规格活动商品修改价格和库存,包含num,newprice,vipprice,为0场景");
		try{
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			List<String> catalogIds = ymtCatalogsIWapper.selectCatalogsByProductId(productId).
											stream().map(x->x.getsCatalogId()).collect(Collectors.toList());
			//创建一个活动  得到活动id
			Integer activityId = ProductManagerCallServiceV2.createIsolationActivityInProcess();
			//报名活动  获得商品在活动中的id
			List<String> aids = ProductManagerCallServiceV2.ApplyActivity(productId, sellerId,catalogIds,activityId, 100,"10");
			//批量修改，num,newprice,vipprice,为0场景
			UpdateProductCatalogsBean updateCatalogBean = new UpdateProductCatalogsBean();
			updateCatalogBean.setProductID(productId);
			updateCatalogBean.setUserID(sellerId);
			
			UpdateProductCatalogDto updateCatalogDto = new UpdateProductCatalogDto();
			updateCatalogDto.setCatalogId(catalogIds.get(0));
			updateCatalogDto.setUserId(sellerId);
			updateCatalogDto.setPrice(50);
			
			
			UpdateProductCatalogDto updateCatalogDto2 = new UpdateProductCatalogDto();
			updateCatalogDto2.setCatalogId(catalogIds.get(1));
			updateCatalogDto2.setUserId(sellerId);
			updateCatalogDto2.setPrice(41);
			
			updateCatalogBean.setCatalogs(Arrays.asList(updateCatalogDto,updateCatalogDto2));
			
			JSONObject ret = updateProductCatalogsCall.callAndGetReturnData(updateCatalogBean);
			Logger.verifyEquals(200, ret.getInt("Code"), "返回码应为200");
			checkPriceAndStock(updateCatalogBean);
			
			//===================================================================================================================
			//批量修改，num,newprice,vipprice,都不为0场景
			updateCatalogDto.setNum(20);
			updateCatalogDto.setNewCustomerPrice(49);
			updateCatalogDto.setVipPrice(48);
			
			updateCatalogDto2.setNum(19);
			updateCatalogDto2.setNewCustomerPrice(39);
			updateCatalogDto2.setVipPrice(38);
			
			ret = updateProductCatalogsCall.callAndGetReturnData(updateCatalogBean);
			Logger.verifyEquals(200, ret.getInt("Code"), "返回码应为200");
			checkPriceAndStock(updateCatalogBean);
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateProductCatalogs_003() {
		Logger.start(true,"多规格活动商品修改价格和库存,价格物流限制校验");
		try{
			//int sellerId = 3383;
			//价格与物流方式不匹配 无法上架"
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV2.initAddSellerProductRequest(3383);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			new YmtProductsIWapper().updateCatalogStatus(productId, 7);
			
			List<String> catalogIds = ymtCatalogsIWapper.selectCatalogsByProductId(productId).
											stream().map(x->x.getsCatalogId()).collect(Collectors.toList());
			
			UpdateProductCatalogsBean updateCatalogBean = new UpdateProductCatalogsBean();
			updateCatalogBean.setProductID(productId);
			updateCatalogBean.setUserID(sellerId);
			
			UpdateProductCatalogDto updateCatalogDto = new UpdateProductCatalogDto();
			updateCatalogDto.setCatalogId(catalogIds.get(0));
			updateCatalogDto.setUserId(sellerId);
			updateCatalogDto.setPrice(2000);
			
			updateCatalogBean.setCatalogs(Arrays.asList(updateCatalogDto));
			
			JSONObject ret = updateProductCatalogsCall.callAndGetReturnData(updateCatalogBean);
			Logger.verifyEquals(201, ret.getInt("Code"), "返回码应为201");
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateProductCatalogs_004() {
		Logger.start(true,"买手不是该商品发布者,修改失败");
		try{
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			List<String> catalogIds = ymtCatalogsIWapper.selectCatalogsByProductId(productId).
											stream().map(x->x.getsCatalogId()).collect(Collectors.toList());
			
			
			//===================================================================================================================
			//批量修改，num,newprice,vipprice,都不为0场景
			UpdateProductCatalogsBean updateCatalogBean = new UpdateProductCatalogsBean();
			updateCatalogBean.setProductID(productId);
			updateCatalogBean.setUserID(sellerId+1);
			
			UpdateProductCatalogDto updateCatalogDto = new UpdateProductCatalogDto();
			updateCatalogDto.setCatalogId(catalogIds.get(0));
			updateCatalogDto.setUserId(sellerId+1);
			updateCatalogDto.setPrice(50);
			updateCatalogDto.setNum(20);
			updateCatalogDto.setNewCustomerPrice(49);
			updateCatalogDto.setVipPrice(48);
			updateCatalogBean.setCatalogs(Arrays.asList(updateCatalogDto));
			
			JSONObject ret = updateProductCatalogsCall.callAndGetReturnData(updateCatalogBean);
			Logger.verifyEquals(201, ret.getInt("Code"), "返回码应为201");
			
			//数据未变
			YmtCatalogsI catalogInSql = ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogIds.get(0));
			updateCatalogDto.setPrice(catalogInSql.getfQuotePrice().doubleValue());
			updateCatalogDto.setNum(catalogInSql.getiNum());
			updateCatalogDto.setNewCustomerPrice(catalogInSql.getfNewCustomerPrice().doubleValue());
			updateCatalogDto.setVipPrice(catalogInSql.getfVipPrice().doubleValue());
			checkPriceAndStock(updateCatalogBean);
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateProductCatalogs_005() {
		Logger.start(true,"价格为0,全部修改失败");
		try{
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			List<String> catalogIds = ymtCatalogsIWapper.selectCatalogsByProductId(productId).
											stream().map(x->x.getsCatalogId()).collect(Collectors.toList());
			
			//===================================================================================================================
			//批量修改，num,newprice,vipprice,都不为0场景
			UpdateProductCatalogsBean updateCatalogBean = new UpdateProductCatalogsBean();
			updateCatalogBean.setProductID(productId);
			updateCatalogBean.setUserID(sellerId);
			
			UpdateProductCatalogDto updateCatalogDto = new UpdateProductCatalogDto();
			updateCatalogDto.setCatalogId(catalogIds.get(0));
			updateCatalogDto.setUserId(sellerId);
			updateCatalogDto.setPrice(0);
			updateCatalogDto.setNum(20);
			updateCatalogDto.setNewCustomerPrice(49);
			updateCatalogDto.setVipPrice(48);
			
			UpdateProductCatalogDto updateCatalogDto2 = new UpdateProductCatalogDto();
			updateCatalogDto2.setCatalogId(catalogIds.get(1));
			updateCatalogDto2.setUserId(sellerId);
			updateCatalogDto2.setPrice(41);
			updateCatalogDto2.setNum(19);
			updateCatalogDto2.setNewCustomerPrice(39);
			updateCatalogDto2.setVipPrice(38);
			updateCatalogBean.setCatalogs(Arrays.asList(updateCatalogDto,updateCatalogDto2));
			
			JSONObject ret = updateProductCatalogsCall.callAndGetReturnData(updateCatalogBean);
			Logger.verifyEquals(400, ret.getInt("Code"), "返回码应为400");
			
			//数据未变
			YmtCatalogsI catalogInSql = ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogIds.get(0));
			updateCatalogDto.setPrice(catalogInSql.getfQuotePrice().doubleValue());
			updateCatalogDto.setNum(catalogInSql.getiNum()); 
			updateCatalogDto.setNewCustomerPrice(catalogInSql.getfNewCustomerPrice().doubleValue());
			updateCatalogDto.setVipPrice(catalogInSql.getfVipPrice().doubleValue());
			
			
			YmtCatalogsI catalogInSql2 = ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogIds.get(1));
			updateCatalogDto2.setPrice(catalogInSql2.getfQuotePrice().doubleValue());
			updateCatalogDto2.setNum(catalogInSql2.getiNum());
			updateCatalogDto2.setNewCustomerPrice(catalogInSql2.getfNewCustomerPrice().doubleValue());
			updateCatalogDto2.setVipPrice(catalogInSql2.getfVipPrice().doubleValue());
			
			checkPriceAndStock(updateCatalogBean);
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateProductCatalogs_006() {
		Logger.start(true,"一个规格不存在,部分修改失败");
		try{
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			List<String> catalogIds = ymtCatalogsIWapper.selectCatalogsByProductId(productId).
											stream().map(x->x.getsCatalogId()).collect(Collectors.toList());
			
			//===================================================================================================================
			//批量修改，num,newprice,vipprice,都不为0场景
			UpdateProductCatalogsBean updateCatalogBean = new UpdateProductCatalogsBean();
			updateCatalogBean.setProductID(productId);
			updateCatalogBean.setUserID(sellerId);
			
			UpdateProductCatalogDto updateCatalogDto = new UpdateProductCatalogDto();
			updateCatalogDto.setCatalogId("dsdfsdf");
			updateCatalogDto.setUserId(sellerId);
			updateCatalogDto.setPrice(1);
			updateCatalogDto.setNum(20);
			updateCatalogDto.setNewCustomerPrice(49);
			updateCatalogDto.setVipPrice(48);
			
			UpdateProductCatalogDto updateCatalogDto2 = new UpdateProductCatalogDto();
			updateCatalogDto2.setCatalogId(catalogIds.get(1));
			updateCatalogDto2.setUserId(sellerId);
			updateCatalogDto2.setPrice(41);
			updateCatalogDto2.setNum(19);
			updateCatalogDto2.setNewCustomerPrice(39);
			updateCatalogDto2.setVipPrice(38);
			updateCatalogBean.setCatalogs(Arrays.asList(updateCatalogDto,updateCatalogDto2));
			
			JSONObject ret = updateProductCatalogsCall.callAndGetReturnData(updateCatalogBean);
			Logger.verifyEquals(200, ret.getInt("Code"), "返回码应为200");
			
			//不存在的规格 数据未变
			YmtCatalogsI catalogInSql = ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogIds.get(0));
			updateCatalogDto.setPrice(catalogInSql.getfQuotePrice().doubleValue());
			updateCatalogDto.setCatalogId(catalogIds.get(0));
			updateCatalogDto.setNum(catalogInSql.getiNum());
			updateCatalogDto.setNewCustomerPrice(catalogInSql.getfNewCustomerPrice().doubleValue());
			updateCatalogDto.setVipPrice(catalogInSql.getfVipPrice().doubleValue());
			
			checkPriceAndStock(updateCatalogBean);
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateProductCatalogs_007() {
		Logger.start(true,"商品不存在,修改失败");
		try{
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			List<String> catalogIds = ymtCatalogsIWapper.selectCatalogsByProductId(productId).
											stream().map(x->x.getsCatalogId()).collect(Collectors.toList());
			
			
			//===================================================================================================================
			//批量修改，num,newprice,vipprice,都不为0场景
			UpdateProductCatalogsBean updateCatalogBean = new UpdateProductCatalogsBean();
			updateCatalogBean.setProductID("sdfadfadfads");
			updateCatalogBean.setUserID(sellerId);
			
			UpdateProductCatalogDto updateCatalogDto = new UpdateProductCatalogDto();
			updateCatalogDto.setCatalogId(catalogIds.get(0));
			updateCatalogDto.setUserId(sellerId+1);
			updateCatalogDto.setPrice(50);
			updateCatalogDto.setNum(20);
			updateCatalogDto.setNewCustomerPrice(49);
			updateCatalogDto.setVipPrice(48);
			updateCatalogBean.setCatalogs(Arrays.asList(updateCatalogDto));
			
			JSONObject ret = updateProductCatalogsCall.callAndGetReturnData(updateCatalogBean);
			Logger.verifyEquals(201, ret.getInt("Code"), "返回码应为201");
			
			
			//数据未变
			YmtCatalogsI catalogInSql = ymtCatalogsIWapper.selectCatalogsByCatalogId(catalogIds.get(0));
			updateCatalogBean.setProductID(productId);
			updateCatalogDto.setPrice(catalogInSql.getfQuotePrice().doubleValue());
			updateCatalogDto.setNum(catalogInSql.getiNum());
			updateCatalogDto.setNewCustomerPrice(catalogInSql.getfNewCustomerPrice().doubleValue());
			updateCatalogDto.setVipPrice(catalogInSql.getfVipPrice().doubleValue());
			checkPriceAndStock(updateCatalogBean);
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateProductCatalogs_008() {
		Logger.start(true,"更新商品的市场价");
		try{
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId1);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();

			List<String> catalogIds = ymtCatalogsIWapper.selectCatalogsByProductId(productId).
					stream().map(x->x.getsCatalogId()).collect(Collectors.toList());
			updateProductCatalogsBean.setProductID(productId);
			updateProductCatalogsBean.setUserID(sellerId1);
			UpdateProductCatalogDto updateCatalogDto = new UpdateProductCatalogDto();
			updateCatalogDto.setCatalogId(catalogIds.get(0));
			updateCatalogDto.setUserId(sellerId1);
			updateCatalogDto.setPrice(50);
			updateCatalogDto.setNum(20);
			updateCatalogDto.setNewCustomerPrice(49);
			updateCatalogDto.setVipPrice(48);
			updateCatalogDto.setMarketPrice(60);
			updateProductCatalogsBean.setCatalogs(Arrays.asList(updateCatalogDto));

			JSONObject ret = updateProductCatalogsCall.callAndGetReturnData(updateProductCatalogsBean);
			Logger.verifyEquals(200, ret.getInt("Code"), "返回码应为201");
			checkPriceAndStock(updateProductCatalogsBean);

		}catch(Exception e){
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_UpdateProductCatalogs_009() {
		Logger.start(true,"更新全球优选礼包商品价格，价格不能低于佣金的价格，优选商品");
		try{
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId1);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();

			List<String> catalogIds = ymtCatalogsIWapper.selectCatalogsByProductId(productId).
					stream().map(x->x.getsCatalogId()).collect(Collectors.toList());

			ProductManagerCallServiceV2.UpdateCatalogCommisions(sellerId1,productId,catalogIds.get(0),addProdReq.getSellerName(),new BigDecimal("0.900"));

			updateProductCatalogsBean.setProductID(productId);
			updateProductCatalogsBean.setUserID(sellerId1);
			UpdateProductCatalogDto updateCatalogDto = new UpdateProductCatalogDto();
			updateCatalogDto.setCatalogId(catalogIds.get(0));
			updateCatalogDto.setUserId(sellerId1);
			updateCatalogDto.setPrice(9);
			updateCatalogDto.setNum(20);
			updateCatalogDto.setNewCustomerPrice(49);
			updateCatalogDto.setVipPrice(48);
			updateCatalogDto.setMarketPrice(60);
			updateProductCatalogsBean.setCatalogs(Arrays.asList(updateCatalogDto));

			JSONObject ret = updateProductCatalogsCall.callAndGetReturnData(updateProductCatalogsBean);
			Logger.verifyEquals(201, ret.getInt("Code"), "返回码应为201");

		}catch(Exception e){
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_UpdateProductCatalogs_010() {
		Logger.start(true,"更新全球优选礼包商品价格，价格不能低于佣金的价格，优选团商品");
		try{
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId1);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			ProductManagerCallServiceV2.AddSellerGlobalPspProduct(sellerId1,productId,2);


			List<String> catalogIds = ymtCatalogsIWapper.selectCatalogsByProductId(productId).
					stream().map(x->x.getsCatalogId()).collect(Collectors.toList());

			ProductManagerCallServiceV2.UpdateCatalogCommisionsV2(sellerId1,productId,catalogIds.get(0),addProdReq.getSellerName(),Arrays.asList(new BigDecimal(7),new BigDecimal(8),new BigDecimal(9),new BigDecimal(10)));

			updateProductCatalogsBean.setProductID(productId);
			updateProductCatalogsBean.setUserID(sellerId1);
			UpdateProductCatalogDto updateCatalogDto = new UpdateProductCatalogDto();
			updateCatalogDto.setCatalogId(catalogIds.get(0));
			updateCatalogDto.setUserId(sellerId1);
			updateCatalogDto.setPrice(9);
			updateCatalogDto.setNum(20);
			updateCatalogDto.setNewCustomerPrice(49);
			updateCatalogDto.setVipPrice(48);
			updateCatalogDto.setMarketPrice(60);
			updateProductCatalogsBean.setCatalogs(Arrays.asList(updateCatalogDto));

			JSONObject ret = updateProductCatalogsCall.callAndGetReturnData(updateProductCatalogsBean);
			Logger.verifyEquals(201, ret.getInt("Code"), "返回码应为201");

		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	
    @Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdateProductCatalogs_011() {
		Logger.start(true," 发布商品澳新版拼邮溯源，低于100元---贝海保税  可以");
		try {
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV3.initAddSellerProductRequest(20323792);
			addProdReq.getProduct().setSecondCategoryId(1130);
			addProdReq.getProduct().setThirdCategoryId(1117);
			addProdReq.getProduct().setPackageDeliveryType(2);
			addProdReq.getProduct().setCatalogStatus(5);

			AddSellerProductCall addSellerProductCall = new AddSellerProductCall();
			//addMock  20200108 update by summing
			ProductManagerCallServiceV3.mockProduct((AddSellerProductCall)addSellerProductCall);

			addSellerProductCall.setData(addProdReq);
			addSellerProductCall.callService();

	        Logger.verifyEquals("200",addSellerProductCall.getString("Code"),"验证code");
	        String productId =addSellerProductCall.getJsonObject().get("Data").getAsJsonObject().get("ProductId").getAsString();
	        
	        updateProductCatalogsBean.setProductID(productId);
			updateProductCatalogsBean.setUserID(20323792);

			List<String> catalogIds = ymtCatalogsIWapper.selectCatalogsByProductId(productId).
					stream().map(x->x.getsCatalogId()).collect(Collectors.toList());
			UpdateProductCatalogDto updateCatalogDto = new UpdateProductCatalogDto();
			CatalogSaveModel ctl = addProdReq.getProduct().getCatalogList().get(0);
			updateCatalogDto.setCatalogId(catalogIds.get(0));
			updateCatalogDto.setUserId(20323792);
			updateCatalogDto.setPrice(ctl.getPrice());
			updateCatalogDto.setNum(ctl.getStock());
			updateCatalogDto.setNewCustomerPrice(ctl.getNewPrice());
			updateCatalogDto.setVipPrice(ctl.getVipPrice());
			updateCatalogDto.setMarketPrice(ctl.getMarketPrice());
			
			updateProductCatalogsBean.setCatalogs(Arrays.asList(updateCatalogDto));
            //updateMock  20200108 update by summing
			ProductManagerCallServiceV3.mockProduct((UpdateProductCatalogsCall)updateProductCatalogsCall);
			updateProductCatalogsCall.setData(updateProductCatalogsBean);
			updateProductCatalogsCall.callService();

			// JSONObject ret = updateProductCatalogsCall.callAndGetReturnData(updateProductCatalogsBean);
			JSONObject ret = new JSONObject(updateProductCatalogsCall.getReturnData());
			//Logger.verifyEquals(201, ret.getInt("Code"), "返回码应为201");
			Logger.verifyEquals(200, ret.getInt("Code"), "200");

		}catch(Exception e){
			Logger.fail(e);
		}
	}
    
    
    @Test
   	@Category({P1.class})
   	@TestCase
   	public void Tc_UpdateProductCatalogs_012() {
   		Logger.start(true,"发布商品澳新版拼邮溯源，高于100元---贝海保税  可以");
   		try {
   			AddSellerProductRequest addProdReq = ProductManagerCallServiceV3.initAddSellerProductRequest(20323792);
   			addProdReq.getProduct().setSecondCategoryId(1130);
   			addProdReq.getProduct().setThirdCategoryId(1117);
   			addProdReq.getProduct().setPackageDeliveryType(2);
   			addProdReq.getProduct().setCatalogStatus(4);
   			AddSellerProductCall addSellerProductCall = new AddSellerProductCall();
			//addMock  20200108 update by summing
			ProductManagerCallServiceV3.mockProduct((AddSellerProductCall)addSellerProductCall);

   			addSellerProductCall.setData(addProdReq);
   	        addSellerProductCall.callService();
   	        Logger.verifyEquals("200",addSellerProductCall.getString("Code"),"验证code");
   	        String productId = addSellerProductCall.getJsonObject().get("Data").getAsJsonObject().get("ProductId").getAsString();
   	        
   	        updateProductCatalogsBean.setProductID(productId);
   			updateProductCatalogsBean.setUserID(20323792);
   			
   			List<String> catalogIds = ymtCatalogsIWapper.selectCatalogsByProductId(productId).
   					stream().map(x->x.getsCatalogId()).collect(Collectors.toList());
   			
   			
   			List<UpdateProductCatalogDto> CatalogSaveModels=new ArrayList<UpdateProductCatalogDto>();
   			System.err.println(catalogIds);
   			for (String catalogId : catalogIds) {
   				CatalogSaveModel ctl = addProdReq.getProduct().getCatalogList().get(0);
   				UpdateProductCatalogDto updateCatalogDto = new UpdateProductCatalogDto();
   				updateCatalogDto.setCatalogId(catalogId);
   				updateCatalogDto.setUserId(20323792);
   				updateCatalogDto.setPrice(ctl.getPrice()+300);
   				updateCatalogDto.setNum(ctl.getStock());
   				updateCatalogDto.setNewCustomerPrice(ctl.getNewPrice()+300);
   				updateCatalogDto.setVipPrice(ctl.getVipPrice()+300);
   				updateCatalogDto.setMarketPrice(ctl.getMarketPrice()+300);
   				CatalogSaveModels.add(updateCatalogDto);
   			}
   			
   			
   			updateProductCatalogsBean.setCatalogs(CatalogSaveModels);
			//updateMock  20200108 update by summing
			ProductManagerCallServiceV3.mockProduct((UpdateProductCatalogsCall)updateProductCatalogsCall);
			updateProductCatalogsCall.setData(updateProductCatalogsBean);
			updateProductCatalogsCall.callService();
			JSONObject ret = new JSONObject(updateProductCatalogsCall.getReturnData());
   			Logger.verifyEquals(200, ret.getInt("Code"), "200");
   			
   			ymtCatalogsIWapper.selectCatalogsByProductId(productId).forEach(b->{System.out.println(b);});

   		}catch(Exception e){
   			Logger.fail(e);
   		}
   	}

    //////////////////////////忽略case ///////////////////////
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_UpdateProductCatalogs_013() {
		Logger.start(true,"发布奢品护航的商品，修改价格，变成不是奢品(全球优选业务下架)");
		try {
			AddSellerProductRequest addProdReq =ProductManagerCallServiceV2.initAddSellerGlobalPspProductRequest(3383);
			addProdReq.getProduct().getCatalogList().get(0).setPrice(10000);
			addProdReq.getProduct().getCatalogList().get(0).setNewPrice(10000);
			addProdReq.getProduct().getCatalogList().get(0).setVipPrice(10000);
			addProdReq.getProduct().getCatalogList().get(0).setMarketPrice(18000);
			String productId = ProductManagerCallServiceV3.AddSellerProduct(addProdReq);

			Thread.sleep(5000);

			//ProductManagerCallServiceV2.EqualsIsLuxury(productId, true);

			updateProductCatalogsBean.setProductID(productId);
			updateProductCatalogsBean.setUserID(3383);

			List<String> catalogIds = ymtCatalogsIWapper.selectCatalogsByProductId(productId).
					stream().map(x->x.getsCatalogId()).collect(Collectors.toList());


			List<UpdateProductCatalogDto> CatalogSaveModels=new ArrayList<UpdateProductCatalogDto>();
			System.err.println(catalogIds);
			for (String catalogId : catalogIds) {

//   				CatalogSaveModel ctl = addProdReq.getProduct().getCatalogList().get(0);
//   				UpdateProductCatalogDto updateCatalogDto = new UpdateProductCatalogDto();
//   				updateCatalogDto.setCatalogId(catalogId);
//   				updateCatalogDto.setUserId(3383);
//   				updateCatalogDto.setPrice(ctl.getPrice()+300);
//   				updateCatalogDto.setNum(ctl.getStock());
//   				updateCatalogDto.setNewCustomerPrice(ctl.getNewPrice()+300);
//   				updateCatalogDto.setVipPrice(ctl.getVipPrice()+300);
//   				updateCatalogDto.setMarketPrice(ctl.getMarketPrice()+300);

				CatalogSaveModel ctl = addProdReq.getProduct().getCatalogList().get(0);
				UpdateProductCatalogDto updateCatalogDto = new UpdateProductCatalogDto();
				updateCatalogDto.setCatalogId(catalogId);
				updateCatalogDto.setUserId(3383);
				updateCatalogDto.setNum(ctl.getStock());
//   				updateCatalogDto.setPrice(300);
//   				updateCatalogDto.setNewCustomerPrice(300);
//   				updateCatalogDto.setVipPrice(300);
//   				updateCatalogDto.setMarketPrice(400);

				updateCatalogDto.setPrice(999999999);
				updateCatalogDto.setNewCustomerPrice(999999999);
				updateCatalogDto.setVipPrice(999999999);
				updateCatalogDto.setMarketPrice(999999999);

				CatalogSaveModels.add(updateCatalogDto);
				break;
			}


			updateProductCatalogsBean.setCatalogs(CatalogSaveModels);
			JSONObject ret = updateProductCatalogsCall.callAndGetReturnData(updateProductCatalogsBean);
			Logger.verifyEquals(200, ret.getInt("Code"), "返回码应为200");
			ProductManagerCallServiceV2.EqualsIsLuxury(productId, false);

		}catch(Exception e){
			Logger.fail(e);
		}
	}



	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_UpdateProductCatalogs_014() {
		Logger.start(true,"发布商品，提升价格，变成奢品(全球优选业务下架)");
		try {
			AddSellerProductRequest addProdReq =ProductManagerCallServiceV2.initAddSellerGlobalPspProductRequest(3383);
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();

			Thread.sleep(5000);

			//	ProductManagerCallServiceV2.EqualsIsLuxury(productId, false);

			updateProductCatalogsBean.setProductID(productId);
			updateProductCatalogsBean.setUserID(3383);

			List<String> catalogIds = ymtCatalogsIWapper.selectCatalogsByProductId(productId).
					stream().map(x->x.getsCatalogId()).collect(Collectors.toList());


			List<UpdateProductCatalogDto> CatalogSaveModels=new ArrayList<UpdateProductCatalogDto>();
			System.err.println(catalogIds);
			for (String catalogId : catalogIds) {

//   				CatalogSaveModel ctl = addProdReq.getProduct().getCatalogList().get(0);
//   				UpdateProductCatalogDto updateCatalogDto = new UpdateProductCatalogDto();
//   				updateCatalogDto.setCatalogId(catalogId);
//   				updateCatalogDto.setUserId(3383);
//   				updateCatalogDto.setPrice(ctl.getPrice()+300);
//   				updateCatalogDto.setNum(ctl.getStock());
//   				updateCatalogDto.setNewCustomerPrice(ctl.getNewPrice()+300);
//   				updateCatalogDto.setVipPrice(ctl.getVipPrice()+300);
//   				updateCatalogDto.setMarketPrice(ctl.getMarketPrice()+300);

				CatalogSaveModel ctl = addProdReq.getProduct().getCatalogList().get(0);
				UpdateProductCatalogDto updateCatalogDto = new UpdateProductCatalogDto();
				updateCatalogDto.setCatalogId(catalogId);
				updateCatalogDto.setUserId(3383);
				updateCatalogDto.setNum(ctl.getStock());
				updateCatalogDto.setPrice(10000);
				updateCatalogDto.setNewCustomerPrice(10000);
				updateCatalogDto.setVipPrice(10000);
				updateCatalogDto.setMarketPrice(18000);
				CatalogSaveModels.add(updateCatalogDto);
			}
			updateProductCatalogsBean.setCatalogs(CatalogSaveModels);
			JSONObject ret = updateProductCatalogsCall.callAndGetReturnData(updateProductCatalogsBean);
			Logger.verifyEquals(200, ret.getInt("Code"), "返回码应为200");
			ProductManagerCallServiceV2.EqualsIsLuxury(productId, true);

		}catch(Exception e){
			Logger.fail(e);
		}
	}

	public static void checkPriceAndStock(UpdateProductCatalogsBean updateCatalogBean) throws Exception{
		String productId = updateCatalogBean.getProductID();
		List<YmtCatalogsI> catalogsInSql = ymtCatalogsIWapper.selectCatalogsByProductId(productId);
		
		//sql check
		updateCatalogBean.getCatalogs().forEach(catalogBean->{
			YmtCatalogsI catalogInSql = catalogsInSql.stream()
												.filter(x->x.getsCatalogId().equals(catalogBean.getCatalogId()))
												.findFirst().orElse(null);
			
			Logger.verifyNotNull(catalogInSql, "sql该数据不该为空 catalogId:"+catalogBean.getCatalogId());
			
			Logger.comment("catalogId:" + catalogBean.getCatalogId());
			Logger.verifyEquals(true, catalogInSql.getiNum().equals(catalogBean.getNum()), "sql库存");
			Logger.verifyEquals(true, catalogInSql.getfQuotePrice().doubleValue()==catalogBean.getPrice(), "sql price");
			Logger.verifyEquals(true, catalogInSql.getfVipPrice().doubleValue()==catalogBean.getVipPrice(), "sql vip price");
			Logger.verifyEquals(true, catalogInSql.getfNewCustomerPrice().doubleValue()==catalogBean.getNewCustomerPrice(), "sql new price");
			if(catalogInSql.getMarketPrice()!=null){
				Logger.verifyEquals(true, catalogInSql.getMarketPrice().doubleValue()==catalogBean.getMarketPrice(), "sql new price");
			}
		});

	}
}
